<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%
	String hospitalNotesJson= (String)request.getAttribute("hospitalNotesJson");
	String pageJson= (String)request.getAttribute("pageJson");
 %>
 <script type="text/javascript" src="${basePath}/static/publics/assets/layer/layer.js"></script>
 <link href="${basePath}/static/layer/layer_defined.css" rel="stylesheet" type="text/css">


<!--内容部分-->    
<div class="list_NR">
    <div class="loc">
        <h3>已归病案查询</h3>
       <!--  <ul class="loc_loc">
          	  病案归档 > 已归病案
        </ul> -->
    </div>
    <div class="list_con_table">
        <input type="hidden" value="${medRecordQuery.totalCounts }" id="totalCountsHidden">
		<form action="${basePath}/medrecord/pigeonholed" method="get" id="queryForm">
		<input type="hidden" name="currentPage" value="${medRecordQuery.currentPage }" id="currentPageHidden">
    	<input type="hidden" name="pageSize" value="${medRecordQuery.pageSize }" id="pageSizeHidden">
    	<div class="search_table">
           <ul class="clearfix" style="margin-bottom:0;">

            <li class="Label_1" style="width:11%">出院日期：&nbsp;</li>
               <li class="Label_2" style="width:27%;">
                   <input style="width:43%;" class="input_box" name="outHospitalStartDate" value='<fmt:formatDate value="${medRecordQuery.outHospitalStartDate}" pattern="yyyy-MM-dd"/>' onFocus="WdatePicker()" type="text" > 
                   - <input style="width:43%" class="input_box" name="outHospitalEndDate"  value='<fmt:formatDate value="${medRecordQuery.outHospitalEndDate}" pattern="yyyy-MM-dd"/>' onFocus="WdatePicker()" type="text" >
               </li>
               <li class="Label_1" style="width:11%">ID号：&nbsp;</li>
               <li class="Label_2">
               	<input class="input_box" type="text" id="scanBarCode"  name="mrId" value='${medRecordQuery.mrId}' />
               </li>
               <li class="Label_1" style="width:11%">出院次数：&nbsp;</li>
               <li class="Label_2">
               	<input class="input_box" type="text"  id="visitNumber" name="visitNumber" value='${medRecordQuery.visitNumber}' />
               </li>
               <li class="Label_1" style="width:11%">身份证号：&nbsp;</li>
               <li class="Label_2" style="width:27%;"><input class="input_box" type="text"  name="idCard" id='' value='${medRecordQuery.idCard}' />
               	 
               </li>
               <li class="Label_1" style="width:11%">出院科室：&nbsp;</li>
               <li class="Label_2" style="text-align:left;padding-left:5px" >
               
               	<select class="input_box"  name="outHospitalOfficeId">
               		<option value="">请选择</option>
               		<c:forEach var="office" items="${offices }"> 
               			<option <c:if test="${medRecordQuery.outHospitalOfficeId==office.id}">selected="selected"</c:if> value="${office.id }">${office.name }</option>
               		</c:forEach>
                	
                	</select>
                </li>
                <li class="Label_1" style="width:11%">患者名：&nbsp;</li>
               <li class="Label_2">
               	<input class="input_box" type="text"  name="name" value='${medRecordQuery.name }' />
               </li>
                
                <li class="Label_1" style="width:11%;height:78px;line-height:78px;">离院方式：&nbsp;</li>
                <li class="Label_2" style="width:88%;height:78px;padding-top:10px;text-align:left;">
                	<c:forEach items="${basicInfo['outHospitalTypes']}" var="outHospitalType">
                		<input type="checkbox" class="check_cl" name="outHospitalTypeIds" value="${outHospitalType.id}" checked="checked"><span>${outHospitalType.name}</span>
                		
                	</c:forEach>
                	<input class="btn_qx" type="button"  onclick="selectAll()" value="全选">
                	<input class="btn_qx" type="button"  onclick="disableAll()" value="取消">
                </li>
                <li class="Label_5">
                    <div class="right">
                    	<a id="Add" onclick="queryFormSubmit()">查询</a>
                    </div>
                </li>
            </ul>
        </div>
     </form>

   </div>

   <table class="Search_tableList"cellpadding="0" cellspacing="0">

       <tr>
           <td class="tdLabel_4">姓名</td>
           <td class="tdLabel_4">身份证号</td>
           <td class="tdLabel_4">ID号</td>
           <td class="tdLabel_4">住院次数</td>
           <td class="tdLabel_4">出院日期</td>
           <td class="tdLabel_4">出院科室</td>
          <!--  <td class="tdLabel_4">离院方式</td> -->
           <td class="tdLabel_4">归档日期</td>
           <td class="tdLabel_4">状态</td>
       </tr>
       
      
       <tbody id="tbody">
       	<%-- <c:forEach var="med" items="${bindList }">
       		<tr>
       			<td class='tdLabel_5'>
       				<div class='imgIcon'><img src='${basePath}/static/publics/images/file.png' alt=''/></div>
       			</td>
       			<td class='tdLabel_5'><fmt:formatDate value="${med.uploadDate}" pattern="yyyy-MM-dd"/></td>
       			<td class='tdLabel_5'>${med.name}</td>
       			<td class='tdLabel_5'>${med.id_number}</td>
       			<td class='tdLabel_5'>${med.treatment_no}</td>
       			<td class='tdLabel_5'><fmt:formatDate value="${med.treatment_date}" pattern="yyyy-MM-dd"/></td>
       			<td class='tdLabel_5'>${med.treatment_type_name}</td>
       			<td class='tdLabel_5'>${med.hospital_name }</td>
       			<td class='tdLabel_5'>${med.comment }</td>
       			<td class='tdLabel_5'>
       				<c:if test="${empty med.first_level_medical_guid }">
       					<a target='_blank' href='${basePath}/bind/pigeonHoleList?id=${med.id}'>绑定</a>
       				</c:if>
       				<c:if test="${not empty med.first_level_medical_guid }">
       					已绑定
       				</c:if>
       			</td>
       		</tr>
       	</c:forEach> --%>
        </tbody>
           
       
    </table>

    <div id="pageList" class="pageList" hidden="true">
        <ul class="pagination clearfix" id="page_plus"></ul>
        <div class="pagination">
            <div>总共：<b id="totalPage">0</b> 条信息    当前页是第 <b id="currentPage">0/0</b>　页</div>
        </div>
    </div>
</div>
<!--script JS部分-->
<script type="text/javascript" src="${basePath}/static/publics/assets/jquery/jquery.min.js"></script>
<script type="text/javascript" src="${basePath}/static/publics/assets/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="${basePath}/static/publics/assets/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${basePath}/static/publics/assets/jqPaginator/jqPaginator.js"></script>
<script type="text/javascript">
	function queryFormSubmit(){
		$("#currentPageHidden").val("1");
		$("#queryForm").submit();
	}
	
	
	$("#scanBarCode").change(function(){
		var $this=$(this);
		var inentity=$this.val();
		if(inentity!=null && inentity!='' && inentity!=undefined){
			if(isContainMark(inentity)){
				var mrId=inentity.split("-")[0];
				var visitNumber=inentity.split("-")[1];
				
				if(!isNumber(visitNumber)){
					alert("请重新扫描条形码!");
					$("#scanBarCode").val("").focus();
					$("#visitNumber").val("");
					return;
				}
				//alert(mrId+"--"+visitNumber);
				$("#scanBarCode").val("").val(mrId);
				$("#visitNumber").val("").val(visitNumber);
				$("#queryForm").submit();
			}
		}
	});
	
	function isNumber(value) {
	    var patrn = /^[0-9]*$/;
	    if (patrn.exec(value) == null || value == "") {
	        return false
	    } else {
	        return true
	    }
	}
	
	
	
	function isContainMark(inentity){
		var reg = RegExp(/-/);
		return reg.test(inentity);
	}
	

	$(function(){
		
		$("#scanBarCode").focus();
		var data= <%=hospitalNotesJson%>;
		var page= <%=pageJson%>;
		var html ="";
		for(var i in data){
			var med=data[i];
			
			html+="<tr data-guid='"+med.firstGuid+"'>"+
		                "<td class='tdLabel_5'>"+(med.patient_name==undefined?'':med.patient_name)+"</td>"+
		                "<td class='tdLabel_5'>"+(med.id_number==undefined?'':med.id_number)+"</td>"+
		               " <td class=tdLabel_5>"+(med.mr_id==undefined?'':med.mr_id)+"</td>"+
		               " <td class=tdLabel_5>"+(med.visit_number==undefined?'':med.visit_number)+"</td>"+
		               " <td class=tdLabel_5>"+(med.out_hospital_date==undefined?'':med.out_hospital_date)+"</td>"+
		                "<td class='tdLabel_5'>"+(med.office_name==undefined?'':med.office_name)+"</td>"+
		             /*   " <td class='tdLabel_5'>"+(med.out_hospital_type_name==undefined?'':med.out_hospital_type_name)+"</td>"+ */
		               " <td class=tdLabel_5>"+(med.trace_date==undefined?'':med.trace_date)+"</td>"+
		               " <td  class='tdLabel_5'><a class='int' onclick='deleteMedicalRecord(this)'>删除</a>&nbsp;<a class='int' onclick='scan(this)'>查看</a>&nbsp;"+(med.special_indication==1?'<a class="int" id="'+med.noteId+'" onclick="addSpecial(this)">添加特殊标示</a>':'特殊病案')+"</td></tr>";
		               
		}
		$("#tbody").html(html);
		if(data.length > 0){
			$("#pageList").show();
			initPage(page);
		}else{
			$("#pageList").attr("hidden",true);
		}
		
	});
	
	
	//查看数据病案事件
    function scan(obj){
		 var target=$(obj);
		 var guid=target.closest("tr").attr("data-guid");
		// window.open('${corePath}/medical_record/searchHomePageIndexForm?visitGuid='+guid);
		 window.open('${basePath}/medical_record/searchHomePageIndexForm?visitGuid='+guid);
	 }
	
	function deleteMedicalRecord(obj){
		layer.confirm("您确认要删除当前记录吗?请确认!", {
            btn : [ '确认删除', '取消删除' ]//按钮
        }, function(index) {
        	layer.close(index);
        	var target=$(obj);
    		var guid=target.closest("tr").attr("data-guid");
    	
        	$.ajax({
        		type:"post",
        		data:{firstGuid:guid},
        		url:"${basePath}/medrecord/deleteMedicalRecord",
        		success:function(data){
        			if(data.success){
        				$("#queryForm").submit();
        			}
        		}
        	})
        	
        }); 	
	}
	
	
	function addSpecial(obj){
		var noteId=$(obj).attr("id");
		//alert(noteId);
		$.ajax({
			type:"post",
			data:{noteId:noteId},
			url:"${basePath}/medical_record/addSpecialMark",
			success:function(data){
				console.log(data);
				if(data=='success'){
					$("#"+noteId).html("特殊病案").removeClass("int");
				}else{
					layer.alert('添加特殊标示失败!',{icon:1});
				}
			}
		})
	}
	
	
	function initPage(page){
		 var totalCounts = page.totalCounts;
		 var pageSize = page.pageSize;
		 var visiblePages = 5;
		 var currentPage = page.currentPage;
		 var totalPages = page.totalPages;
		 $('#page_plus').jqPaginator({

		        totalCounts: totalCounts,
		        pageSize:pageSize,
		        visiblePages: visiblePages,
		        currentPage: currentPage,

		        first:'<li class="first"><a href="javascript:void(0);">首页</a></li>',
		        prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
		        next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
		        last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
		        page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
		        onPageChange: function (num,type) {

		     		if(type !='init'){
		     			$("#currentPageHidden").val(num);
						$("#pageSizeHidden").val(pageSize);
						$("#queryForm").submit();
					}else{
						 $("#totalPage").html(totalCounts);
			            $("#currentPage").html(num+"/"+totalPages);
			            $("#currentPageHidden").val(currentPage);
					    $("#pageSizeHidden").val(pageSize);
					}
		           
		        }
		    });

	}
	
	//获取checkbox值
  /* function getFormVals(name){
 			var arr = [];
 			$("input[type='checkbox'][name='"+name+"']:checked").each(function(){
 				arr.push($(this).val());	

 			});
 			return arr.toString();
 	}
	 */
 function selectAll(){
 	  $('input[name="outHospitalTypeIds"]').each(function(){  
           //此处如果用attr，会出现第三次失效的情况  
           $(this).prop("checked",true);  
       });  
 }

 function disableAll(){
 	  $('input[name="outHospitalTypeIds"]').each(function(){  
           //此处如果用attr，会出现第三次失效的情况  
           $(this).prop("checked",false);  
       });  
 }
</script>
